#include "Iterator.h"


ConcreteAggregate::ConcreteAggregate(int size)
{
	a_pData = new DATA[size];	

	for (int i = 0; i < size; ++i)
	{
		a_pData[i] = i;
	}

	a_size = size;
}


ConcreteAggregate::~ConcreteAggregate()
{
	delete []a_pData;
	a_pData = NULL;
	a_size = 0;
}

int ConcreteAggregate::GetSize()
{
	return a_size;
}

Iterator* ConcreteAggregate::CreateIterator()
{
	return new ConcreteIterator(this);
}

DATA ConcreteAggregate::GetItem(int index)
{
	return a_pData[index];
}

ConcreteIterator::ConcreteIterator(Aggregate* pAggregate):a_pAggregate(pAggregate),a_index(0)
{
	a_size = a_pAggregate->GetSize();
}
void ConcreteIterator::First()
{
	a_index = 0;
}

void ConcreteIterator::Next()
{
	++a_index;
}

bool ConcreteIterator::IsDone()
{
	return (a_index == a_size);
}

DATA ConcreteIterator::CurrentItem()
{
	return a_pAggregate->GetItem(a_index);
}
